package com.example.demo.controller;

import com.example.demo.service.UsersService;
import com.example.demo.vo.ResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.server.Session;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpSession;

@RestController
public class LoginController {
@Autowired
    private UsersService usersService;
    @PostMapping("/login")
    public ResponseVO login(String username, String password, HttpSession session) {
        System.out.println("username: " + username);
        System.out.println("password: " + password);
        ResponseVO result = usersService.loginUsers(username, password);
        if (result.getStatus() == 1) {
            session.setAttribute("user", username); // 把用户存入 Session
        }
        return result;
    }
    @PostMapping("/loginout")
    public ResponseVO loginout(HttpSession session){
        session.removeAttribute("user");
        return ResponseVO.success("成功退出");
    }
}